using System.Collections;
using UnityEngine;

namespace __Naptime
{
	public class RewiredVibrations : MonoBehaviour
	{
		public enum VibrationType
		{
			Selection = 0,
			Success = 1,
			Warning = 2,
			Failure = 3,
			LightImpact = 4,
			MediumImpact = 5,
			HeavyImpact = 6,
			RigidImpact = 7,
			None = 8
		}

		private Coroutine vibrateCoroutine;

		private static int _sdkVersion = -1;

		public static float LightDuration = 0.1f;

		public static float MediumDuration = 0.2f;

		public static float HeavyDuration = 0.4f;

		public static float RigidAmplitude = 0.4f;

		public static float LightAmplitude = 0.01f;

		public static float MediumAmplitude = 0.03f;

		public static float HeavyAmplitude = 0.05f;

		public static float RigidDuration = 0.01f;

		private static float[] _successPattern = new float[4] { 0f, LightDuration, LightDuration, HeavyDuration };

		private static float[] _successPatternAmplitude = new float[4] { 0f, LightAmplitude, 0f, HeavyAmplitude };

		private static float[] _warningPattern = new float[4] { 0f, HeavyDuration, LightDuration, MediumDuration };

		private static float[] _warningPatternAmplitude = new float[4] { 0f, HeavyAmplitude, 0f, MediumAmplitude };

		private static float[] _rigidImpactPatternAmplitude = new float[2] { 0f, RigidAmplitude };

		private static float[] _failurePattern = new float[8] { 0f, MediumDuration, LightDuration, MediumDuration, LightDuration, HeavyDuration, LightDuration, LightDuration };

		private static float[] _failurePatternAmplitude = new float[8] { 0f, MediumAmplitude, 0f, MediumAmplitude, 0f, HeavyAmplitude, 0f, LightAmplitude };

		public static RewiredVibrations I;

		public virtual void TriggerSelection()
		{
			VibrateUsingType(VibrationType.Selection);
		}

		public virtual void TriggerSuccess()
		{
			VibrateUsingType(VibrationType.Success);
		}

		public virtual void TriggerWarning()
		{
			VibrateUsingType(VibrationType.Warning);
		}

		public virtual void TriggerFailure(bool bypassHaptics = true)
		{
			VibrateUsingType(VibrationType.Failure);
		}

		public virtual void TriggerLightImpact()
		{
			VibrateUsingType(VibrationType.LightImpact);
		}

		public virtual void TriggerMediumImpact()
		{
			VibrateUsingType(VibrationType.MediumImpact);
		}

		public virtual void TriggerHeavyImpact()
		{
			VibrateUsingType(VibrationType.HeavyImpact);
		}

		public void GetVibrationScheme(VibrationType type, out float[] pattern, out float[] amplitudes, out int repeat)
		{
			pattern = new float[1];
			amplitudes = new float[1];
			repeat = -1;
			switch (type)
			{
			case VibrationType.Selection:
				pattern = new float[1] { LightDuration };
				amplitudes = new float[1] { LightAmplitude };
				repeat = -1;
				break;
			case VibrationType.Success:
				pattern = _successPattern;
				amplitudes = _successPatternAmplitude;
				repeat = -1;
				break;
			case VibrationType.Warning:
				pattern = _warningPattern;
				amplitudes = _warningPatternAmplitude;
				repeat = -1;
				break;
			case VibrationType.Failure:
				pattern = _failurePattern;
				amplitudes = _failurePatternAmplitude;
				repeat = -1;
				break;
			case VibrationType.LightImpact:
				pattern = new float[1] { LightDuration };
				amplitudes = new float[1] { LightAmplitude };
				repeat = -1;
				break;
			case VibrationType.RigidImpact:
				pattern = new float[1] { RigidDuration };
				amplitudes = new float[1] { RigidAmplitude };
				repeat = -1;
				break;
			case VibrationType.MediumImpact:
				pattern = new float[1] { MediumDuration };
				amplitudes = new float[1] { MediumAmplitude };
				repeat = -1;
				break;
			case VibrationType.HeavyImpact:
				pattern = new float[1] { HeavyDuration };
				amplitudes = new float[1] { HeavyAmplitude };
				repeat = -1;
				break;
			}
		}

		public void VibrateUsingType(VibrationType vibrationType, bool bypassHaptics = false)
		{
			GetVibrationScheme(vibrationType, out var pattern, out var amplitudes, out var _);
			VibrateWaveForm(pattern, amplitudes);
		}

		private void Awake()
		{
			I = this;
		}

		public void VibrateOneShot(float time, float amplitude, int playerIndex = 0, bool bypassHaptics = false)
		{
			PlayerVibrate(time, amplitude, playerIndex);
		}

		public void VibrateWaveForm(float[] timings, float[] amplitudes, int playerIndex = 0, bool bypassHaptics = false)
		{
			if (vibrateCoroutine != null)
			{
				StopCoroutine(vibrateCoroutine);
			}
			vibrateCoroutine = StartCoroutine(Vibrate(timings, amplitudes, playerIndex));
		}

		private IEnumerator Vibrate(float[] timings, float[] amplitudes, int playerIndex = 0)
		{
			for (int i = 0; i < timings.Length; i++)
			{
				if (timings[i] != 0f)
				{
					PlayerVibrate(timings[i], amplitudes[i], playerIndex);
					yield return new WaitForSeconds(timings[i]);
				}
			}
			vibrateCoroutine = null;
		}

		public void PlayerVibrate(float duration, float strength, int playerIndex = 0, bool bypassHaptics = false)
		{
		}
	}
}
